package com.aaa.day1104.demo2;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @author:LiWei
 * @date:2022年11月04日12:42
 */
public class Test2 {
    public static void main(String[] args) {
        List<Person> personArrayList = new ArrayList<>();
        personArrayList.add(new Person("张三",21,"中国",'F'));
        personArrayList.add(new Person("张四",20,"中国",'F'));
        personArrayList.add(new Person("张五",40,"中国",'F'));
        personArrayList.add(new Person("李四",25,"美国",'F'));
        personArrayList.add(new Person("李五",19,"中国",'F'));
        personArrayList.add(new Person("赵四",30,"英国",'F'));

        //年龄大于18的
        personArrayList.stream().filter(item->{
            return item.getAge()>18;
        }).forEach(item-> System.out.println(item));

        //找出所有中国人的数量。
        long count = personArrayList.stream().filter(item -> item.getCountry().equals("中国")).count();
        System.out.println(count);
    }
}
class Person {
    private String name;
    private Integer age;
    private String country;
    private char sex;

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", country='" + country + '\'' +
                ", sex=" + sex +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }

    public Person(String name, Integer age, String country, char sex) {
        this.name = name;
        this.age = age;
        this.country = country;
        this.sex = sex;
    }
}